package ca.camosun.chatbox.network;

import java.util.ArrayList;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
import java.util.TreeSet;

import ca.camosun.chatbox.network.Room;
import ca.camosun.chatbox.profile.Profile;

public class FakeRoomProximityController extends TimerTask {

	Timer timer;
	private Set<Profile> people;
	private Room<Profile> chatRoom;
	static int fakeProfileCounter;

	private ArrayList<Profile> fakeProfiles = new ArrayList<Profile>();

	public FakeRoomProximityController(boolean useTimer) {
		people = new TreeSet<Profile>();
		chatRoom = new Room<Profile>();
		
		fakeProfileCounter = 0;
		composeFakeProfiles();
		
		if(useTimer) {
			timer = new Timer();
			timer.schedule(new TimerTask() {
				@Override
				public void run() {
					findAllProfiles();
				}
			}, 0, 5000);
		}
		
	}

	public void composeFakeProfiles() {
		Profile profile0 = new Profile("AAA");
		Profile profile1 = new Profile("BBB");
		Profile profile2 = new Profile("CCC");
		Profile profile3 = new Profile("DDD");
		Profile profile4 = new Profile("EEE");
		Profile profile5 = new Profile("FFF");
		Profile profile6 = new Profile("GGG");
		Profile profile7 = new Profile("HHH");
		Profile profile8 = new Profile("III");
		Profile profile9 = new Profile("JJJ");
		
		fakeProfiles.add(profile0);
		fakeProfiles.add(profile1);
		fakeProfiles.add(profile2);
		fakeProfiles.add(profile3);
		fakeProfiles.add(profile4);
		fakeProfiles.add(profile5);
		fakeProfiles.add(profile6);
		fakeProfiles.add(profile7);
		fakeProfiles.add(profile8);
		fakeProfiles.add(profile9);
	}
	
	public void findAllProfiles() {
		
		people.clear();
		
		for(int i = 0; i <= fakeProfileCounter; i++) {
			Profile aProfile = fakeProfiles.get(i); 
			people.add(aProfile);
		}
		
		fakeProfileCounter++;
		
		if(fakeProfileCounter > fakeProfiles.size()) {
			fakeProfileCounter = 0;
		}
		
		updateChatRoomList();
		
	}
	
	public void updateChatRoomList() {
		chatRoom.changeRoomContents(people);
	}
	
	public int getChatRoomSize() {
		return chatRoom.size();
	}
	
	public void run() {
		
	}
	
}
